package com.occupation_health.model;

import java.util.List;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.authz.permission.WildcardPermission;
import com.jfinal.plugin.activerecord.Model;

public class Authority extends Model<Authority> {
	public static final Authority dao = new Authority().dao();

	public List<Permission> getPermissionByRole(String roleString) {
		List<Permission> result = null;
		List<Authority> authorities = Authority.dao
				.find("SELECT a.* FROM oh_auth a INNER JOIN oh_role_auth r_a ON r_a.a_id=a.a_id WHERE r_a.r_id='"
						+ roleString + "'");
		for(Authority auth:authorities){
			result.add((Permission) new WildcardPermission(auth.getStr("action")));
		}
		return result;
	}
}
